// pages/record/index.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showShiJuan: false,
    spinShow: false,
    loadMoreLoad: false,
    loadMoreTip: '暂无数据',
    queryParam: {
      pageIndex: 1,
      pageSize: 3,
      paperName:""
    },
    tableData: [],
    total: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      spinShow: true
    });
    
    //console.log('pageIndex==1====='+this.data.queryParam.pageIndex);
    //console.log('total++++1+++'+this.data.total);
    this.search(true)
  },
  //搜索框变化
  searchValueOnChange: function (e) {
    this.setData({
      queryParam: {
        pageIndex: 1,
        pageSize: 3,
        paperName:e.detail.value
      },
    })
  },
  //搜索
  search: function(override){
    var that = this;
    var empinfo = wx.getStorageSync('empinfo')
    //console.log('人员ID'+empinfo.employeeId)
    
    app.formPost('/wx/test/get-transcript-record-ls',{
      shijuanName: that.data.queryParam.paperName,
      pageIndex: that.data.queryParam.pageIndex,
      pageSize: 3,
      employeeId: empinfo.employeeId,
    }).then(res=>{
      that.setData({
        spinShow: false
      });
      wx.stopPullDownRefresh()
        if(res.code == 200){
          //console.log(res.transcriptInfoList)

          that.setData({
            ['queryParam.pageIndex']: res.transcriptInfoList.currPage,
            //['queryParam.pageIndex']: res.transcriptInfoList.size,
            tableData: override ? res.transcriptInfoList.list : that.data.tableData.concat(res.transcriptInfoList.list),
            total: res.transcriptInfoList.totalPage,
          });
          if (res.transcriptInfoList.currPage >= res.transcriptInfoList.totalPage) {
            that.setData({
              loadMoreLoad: false,
              loadMoreTip: '暂无数据'
            });
          }
          // if(res.transcriptInfoList.length >0 ){
            
          // }else{
          //   that.setData({
          //     loadMoreLoad: false,
          //     loadMoreTip: '暂无数据'
          //   });
          // }
          
      }
    }).catch(e => {
      wx.showModal({
        title: e
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
    this.setData({
      ['queryParam.pageIndex']: 1
    });
    this.search(true)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //console.log('pageIndex==2222=====');
    this.setData({
      spinShow: true,
      queryParam: {
        pageIndex: 1,
        pageSize: 3,
        paperName: ''
      },
    });
    this.search(true)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      spinShow: true
    });
    if (!this.loading) {
      this.setData({
        ['queryParam.pageIndex']: 1
      });
      this.search(true)
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    //console.log('pageIndex======='+this.data.queryParam.pageIndex);
    //console.log('total+++++++'+this.data.total);
    if (!this.loading && this.data.queryParam.pageIndex < this.data.total) {
      this.setData({
        loadMoreLoad: true,
        loadMoreTip: '正在加载'
      });
      
      this.setData({
        ['queryParam.pageIndex']: this.data.queryParam.pageIndex + 1
      });
      this.search(false)
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})